package com.sgb.kjwl.view.ui.fragment.packers;

import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentTeamServiceBinding;
import com.swgk.core.view.adapter.CommPagerAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
/**
 * @author 王彬臣
 * @date 2021/9/3
 * description: 企业网站-工队经营
 */
public class TeamServiceFragment extends AppLazyFragment {
    private FragmentTeamServiceBinding mBinding;
    private final String[] tabMenu = {"经营工队", "团队人员", "专业设备", "工程业绩","工种报价"};
    private TextView selectTextView;
    private String websiteNo;

    public static TeamServiceFragment newInstance(String websiteNo){
        TeamServiceFragment teamServiceFragment= new TeamServiceFragment();
        Bundle args = new Bundle();
        args.putString("websiteNo", websiteNo);
        teamServiceFragment.setArguments(args);
        return teamServiceFragment;
    }
     
    @Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_team_service, container, false);
        if (getArguments() != null) {
            websiteNo = getArguments().getString("websiteNo");
        }
        return mBinding.getRoot();
    }

    @Override
    protected void initView() {
        initTabLayout();

        mBinding.tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (selectTextView == null) {
                    selectTextView = new TextView(getActivity());
                }
                selectTextView.setTextSize(15);
                selectTextView.setTextColor(getResources().getColor(R.color.color_main));
                selectTextView.setText(tab.getText());
                selectTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tab.setCustomView(selectTextView);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
    }

    @Override
    protected void onLazyLoad() {

    }

    private void initTabLayout() {
        ArrayList<Fragment> mFragments = new ArrayList<>();
        mFragments.add(TeamListFragment.newInstance(websiteNo));
        mFragments.add(TeamCrewFragment.newInstance(websiteNo));
        mFragments.add(TeamDeviceFragment.newInstance(websiteNo));
        mFragments.add(PerformanceFragment.newInstance(websiteNo));
        mFragments.add(TeamOfferFragment.newInstance(websiteNo));

        CommPagerAdapter mAdapter = new CommPagerAdapter(getChildFragmentManager(), mFragments, tabMenu);
        mBinding.vpNeed.setAdapter(mAdapter);
        mBinding.vpNeed.setOffscreenPageLimit(tabMenu.length);
        mBinding.tab.setupWithViewPager(mBinding.vpNeed);
    }
}
